import service from "../uitils/request"

export const appInfoApi = (appName) => {
    return service({
        url: `/manage/app/${appName}`,
        method: 'GET'
    })
}

export const appListApi = () => {
    return service({
        url: "/manage/app/list",
        method: 'GET'
    })
}
export const appPageApi = (params) => {
    return service({
        url: "/manage/app/page",
        method: 'GET',
        params
    })
}

export const deleteAppApi = (appName) => {
    return service({
        url: `/manage/app/${appName}`,
        method: 'DELETE',
    })
}

export const deployGroupListApi = (appName) => {
    return service({
        url: "/manage/deployGroup/list",
        method: 'GET',
        params: {
            appName: appName
        }
    })
}

export const getDeployGroupApi = (deployGroupId) => {
    return service({
        url: `/manage/deployGroup/${deployGroupId}`,
        method: 'get'
    })
}
export const closeGroupDeployApi = (deployGroupId) => {
    return service({
        url: `/manage/deployGroup/closeDeploy/${deployGroupId}`,
        method: 'PUT'
    })
}

export const databaseInstanceListApi = (appName) => {
    return service({
        url: "/manage/database/list",
        method: 'GET',
        params: {
            appName: appName
        }
    })
}

export const appInstanceListApi = (appName, deployGroupName) => {
    return service({
        url: "/manage/appInstance/list",
        method: 'GET',
        params: {
            appName: appName,
            deployGroupName: deployGroupName
        }
    })
}

export const saveAppApi = (data) => {
    return service({
        url: "/manage/app/saveApp",
        method: 'POST', data
    })
}

export const saveDeployGroupApi = (data) => {
    return service({
        url: "/manage/deployGroup/save",
        method: 'POST', data
    })
}

export const deleteDeployGroupApi = (groupId) => {
    return service({
        url: `/manage/deployGroup/${groupId}`,
        method: 'DELETE'
    })
}


export const hostInstancePageApi = (params) => {
    return service({
        url: `/manage/host/page`,
        method: 'GET',
        params
    })
}

export const saveHostPageApi = (data) => {
    return service({
        url: `/manage/host`,
        method: 'POST',
        data
    })
}

export const appInstancePageApi = (params) => {
    return service({
        url: `/manage/appInstance/page`,
        method: 'GET',
        params
    })
}

export const installLog = (params) => {
    return service({
        url: `log/install/installLogListener`,
        method: 'GET',
        timeout: 1000 * 60 * 10,
        params
    })
}

export const saveAppInstanceApi = (data) => {
    return service({
        url: `/manage/appInstance`,
        method: 'POST',
        data
    })
}

export const databaseInstancePageApi = (params) => {
    return service({
        url: `/manage/database/page`,
        method: 'GET',
        params
    })
}

export const saveDatabaseInstanceApi = (data) => {
    return service({
        url: `/manage/database`,
        method: 'POST',
        data
    })
}


export const sshFileListApi = (hostId, dir) => {
    return service({
        url: `/sshFile/list`,
        method: 'GET',
        params: {
            hostId: hostId, dir: dir
        }
    })
}

export const downloadSshFileApi = (hostId, fileName) => {
    return service({
        url: `/sshFile/download`,
        method: 'GET',
        responseType: 'blob',
        params: {
            hostId: hostId, fileName: fileName
        }
    })
}


export const getSystemSettingApi = () => {
    return service({
        url: `/getSystemSetting`,
        method: 'get'
    })
}

export const saveSystemSettingApi = (data) => {
    return service({
        url: `/saveSystemSetting`,
        method: 'POST',
        data
    })
}

export const testSshConnectApi = (data) => {
    return service({
        url: `/sshConnect/test`,
        method: 'PUT',
        data
    })
}


